package com.ffox.result;

import java.io.Serializable;

    public class Result<T> implements Serializable {
        private static final long serialVersionUID = 1L;

        // 状态码
        private int code;
        // 消息
        private String message;
        // 数据
        private T data;

        public Result() {}

        public Result(int code, String message, T data) {
            this.code = code;
            this.message = message;
            this.data = data;
        }

        // Getters and Setters
        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

        public T getData() {
            return data;
        }

        public void setData(T data) {
            this.data = data;
        }

        // 成功返回结果
        public static <T> Result<T> success(String message,T data) {
            return new Result<>(200, message, data);
        }

        // 失败返回结果
        public static <T> Result<T> fail(String message) {
            return new Result<>(500, message, null);
        }
    }
